package com.yueya.business.qa.service;

import java.util.Map;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.yueya.business.qa.model.Qa;

public class QaService {

	@SuppressWarnings("rawtypes")
	public Page pagination(int pageNumber, int pageSize, Map<String, String> map) {
		String select = "SELECT a.* ";
		StringBuffer sb = new StringBuffer();
		sb.append(" FROM t_qa a ");
		sb.append(" WHERE a.del_flag = 0 ");
		if (StrKit.notBlank(map.get("name"))) {
			sb.append(" AND a.question like '%" + map.get("name") + "%' ");
		}
		sb.append(" order by order_id  ");
		String sqlExceptSelect = sb.toString();
		Page page = Qa.dao.paginate(pageNumber, pageSize, select, sqlExceptSelect);
		return page;

	}

	public boolean remove(String id) {
		String sql = "update t_qa set del_flag =1 where id =?";
		int num = Db.update(sql, id);

		if (num > 0) {
			return true;
		}
		return false;
	}

	public boolean bathremove(String idsStr) {
		boolean bl = false;
		if (idsStr != null) {
			String[] ids = idsStr.split(";");

			for (int i = 0; i < ids.length; i++) {
				if (!"".equals(ids[i]) && ids[i] != null) {

					if (remove(ids[i])) {
						bl = true;
					} else {
						bl = false;
						break;
					}
				}
			}
		}
		return bl;
	}

}
